package com.oocl.o2o.admin.aspect;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import org.apache.commons.codec.binary.Base64;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import com.oocl.o2o.admin.entity.Manager;

@Component
@Aspect
public class ManagerEncrypt {
	
	
	
	@Around(value="execution(* com.oocl.o2o.admin.service.ManagerService.findByUnameAndPassword(..))")
	public Object encrypt(ProceedingJoinPoint point) throws NoSuchAlgorithmException{
		//获得接入点传入的参
		
		String uname = (String) point.getArgs()[0];
		String pwd = (String) point.getArgs()[1];
		
		MessageDigest md5 = MessageDigest.getInstance("MD5");
		Object o= null;
		byte[] b = Base64.encodeBase64(md5.digest(pwd.getBytes()));
		try {
			o = point.proceed(new Object[]{uname,new String(b)});
		} catch (Throwable e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return o;
		
	}
	
}
